import config from './config';
class httpapi {
	$get(url,data={}) {
		let u = config.url + url;
		const request_data=Object.keys(data).map(z=>`${z}=${data[z]}`).join('&');
		if(request_data) u+='?'+request_data;
		return new Promise((resolve, reject) => {
			uni.request({
				url: u,
				header: {
					"u_id": uni.getStorageSync('u_id')
				},
				success(data) {
					const { state, msg } = data.data;
					if (state) {
						resolve(msg);
					} else {
						reject(msg);
					}
				},
				fail(data) {
					reject(data);
				}
			})
		})
	}
	$post(url, data) {
		return new Promise((resolve, reject) => {
			uni.request({
				url: config.url + url,
				method: "POST",
				header: {
					"u_id": uni.getStorageSync("u_id")
				},
				data,
				success(data) {
					if (state) {
						resolve(msg);
					} else {
						reject(msg);
					}
				},
				fail(data){
					reject(data);
				}
			})
		});
	}
}
export default new httpapi();